package kentriko;

import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.SwingWorker;

public class grab extends SwingWorker {

    XMLReader xml;
    private String url;
    private JProgressBar bar;
    String result;
    private JLabel myLabel;

    public grab(String inUrl, JProgressBar inBar, JLabel inLabel) {
        xml = null;
        result = "";
        myLabel = inLabel;
        url = inUrl;
        bar = inBar;
    }

    public void stop() {
        bar.setIndeterminate(false);
    }

    protected String doInBackground() throws Exception {
        String id = "";
        String tok[] = url.split("/");
        //int len = tok.length;
        //int i = 0;

        for (int j = 0; j < tok.length; j++) {
            String string = tok[j];
            if ((string.length() > 13) && (string.startsWith("v"))) {
                //StringTokenizer st = new StringTokenizer(string, "?");
                id = string;
            }
        }


        String details_url = "http://www.veoh.com/rest/video/" + id + "/details";
        System.out.println(details_url);
        xml = new XMLReader(details_url, myLabel);

        return xml.getResult();
    }
}
